﻿using System.ComponentModel;
using Airborne.ScrumPoker.Model.Cards;

namespace Airborne.ScrumPoker.Module.ProductOwner.Model
{
    public class Player : INotifyPropertyChanged
    {
        #region Events

        #region PropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventArgs args = new PropertyChangedEventArgs(propertyName);
            OnPropertyChanged(args);
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, args);
            }
        }

        #endregion
        #endregion

        #region Fields

        private string clientName;
        private ICard vote;
        private bool voteShown;
        private bool voted;
        #endregion

        #region Properties
        public string ClientName
        {
            get
            {
                return clientName;
            }
            set
            {
                if (clientName != value)
                {
                    clientName = value;
                    RaisePropertyChanged("ClientName");
                }
            }
        }

        public ICard Vote
        {
            get
            {
                return vote;
            }
            set
            {
                if (vote != value)
                {
                    vote = value;
                    RaisePropertyChanged("Vote");
                    Voted = (value != null);
                }
            }
        }

        public bool VoteShown
        {
            get
            {
                return voteShown;
            }
            set
            {
                if (voteShown != value)
                {
                    voteShown  = value;
                    RaisePropertyChanged("VoteShown");
                }
            }

        }

        public bool Voted
        {
            get
            {
                return voted;
            }
            set
            {
                if (voted != value)
                {
                    voted = value;
                    RaisePropertyChanged("Voted");
                }
            }
        }

        #endregion

        #region Methods
        public void Reset()
        {
            VoteShown = false;
            Vote = null;
            Voted = false;
        }
        #endregion
    }
}
